package a07_二叉树;

/**
 * <p>
 * a04_翻转二叉树
 * </p>
 *
 * @author flyduck
 * @since 2024-08-26
 */
public class a06_翻转二叉树 {

    public TreeNode invertTree(TreeNode root) {
        if(root == null){
            return null;
        }

        //对左右树进行反转
        reverse(root);

        //左右树分别反转
        invertTree(root.left);
        invertTree(root.right);
        return root;
    }

    private void reverse(TreeNode root) {
        TreeNode temp = root.left;
        root.left = root.right;
        root.right = temp;
    }

}
